package java1226;
//1:类
public class Student {
    //2:成员变量
    String name;
    int age;
    String major;
    //3:构造方法
    public Student() {
    }//空构造方法，生成时点击无选择
    public Student(String name, int age, String major) {
        this.name = name;
        this.age = age;
        this.major = major;
    }//有参数构造方法，生成时选择参数
    //4:getters和setters
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getMajor() {
        return major;
    }
    public void setMajor(String major) {
        this.major = major;
    }
//    5:toString方法
    //重写toString方法，返回对象的字符串表示，即打印对象信息
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", major='" + major + '\'' +
                '}';
    }
//    6：主方法中创建对象
    public static void main(String[] args) {
        Student s1 = new Student();
        s1.setName("老四");
        s1.setAge(57);
        s1.setMajor("开沟机");
        Student s2 = new Student("常爷",27,"开出租车");
        Student s3 = new Student("七哥",19,"收保护费");
        Student s4 = new Student("长海",35,"理发");
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);

    }

}
